// EJWork.h : main header file for the EJWORK application
//

#if !defined(AFX_EJWORK_H__3A6B6BDA_E548_4606_98A4_717C0AC8D892__INCLUDED_)
#define AFX_EJWORK_H__3A6B6BDA_E548_4606_98A4_717C0AC8D892__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"       // main symbols

#define EJW_VERSION		"EJW-1.0.7"

#import <msxml2.dll>

#define HIT_OUTSIDE			0
#define HIT_LEFTTOP			1
#define HIT_RIGHTTOP		2
#define HIT_RIGHTBOTTOM		3
#define HIT_LEFTBOTTOM		4
#define HIT_TOP				5
#define HIT_RIGHT			6
#define HIT_BOTTOM			7
#define HIT_LEFT			8
#define HIT_INSIDE			9

#pragma warning(disable:4786)

class CEJAnnoItem
{
public:
	CEJAnnoItem();
	virtual ~CEJAnnoItem();

public:
	CString	cls;
	CString	dat;

public:
	void Reset();
	BYTE IsEmpty() const;
	void Set(const CString& c,const CString& d);
	void Copy(const CEJAnnoItem& src);
};

#define NUM_ANNO_ITEM	10
class CEJAnno
{
public:
	CEJAnno();
	virtual ~CEJAnno();

public:
	long chIndex;
	CString text;
	CRect	box;
	CRect	boxInView;
	CRect	gripInView[8];
	CRect	inBound;

	CEJAnnoItem	item[NUM_ANNO_ITEM];

public:
	void PostPage2Disp();
	BYTE HitTest(const CPoint& pt) const;
	BYTE FindByCls(LPCSTR cls,LPWORD index);
	BYTE FindEmpty(LPWORD index);
	void Output(WORD index,CString& str);
	void Reset();
	void Copy(const CEJAnno& src);
	void Save(MSXML2::IXMLDOMDocumentPtr odom,MSXML2::IXMLDOMElementPtr root);
	void Load(MSXML2::IXMLDOMElementPtr root);
	void Fit(long cx,long cy);
};

#define NUM_ANNO_PER_PAGE	32

class CEJPage
{
public:
	CEJPage();
	virtual ~CEJPage();

public:
	DWORD	id;
	CString	fileName;

	CString	text;

	BYTE*	pix;
	CSize	size;
	int		chnls;

	long	chIndex;

	WORD	num;
	CEJAnno	anno[NUM_ANNO_PER_PAGE];

	WORD	pageID;
	CString	catl;
	CString	subCatl;

public:
	void RGBA_FPX_to_BGRA(BYTE* data,int width,int height);
	void LoadJPEG(LPCSTR baseDir);
	void Unload();
	void PreLoad(LPCSTR baseDir);

	void Page2Disp(const CRect& disp,const CPoint& src,CPoint& dst);
	void Disp2Page(const CRect& disp,const CPoint& src,CPoint& dst);
	
	void Page2Disp(const CRect& disp,const CRect& src,CRect& dst);
	void Disp2Page(const CRect& disp,const CRect& src,CRect& dst);

	void Page2Disp(const CRect& disp,CEJAnno& anno);
	WORD HitTest(const CRect& disp,const CPoint& pt,LPBYTE hitIndex);
	void AddAnno(const CRect& disp,const CRect& rc);
	void DelAnno(WORD index);

	void Input(const CString str,long index);
	void Output(CString &str);

	void Save(MSXML2::IXMLDOMDocumentPtr odom,MSXML2::IXMLDOMElementPtr root);
	void Load(MSXML2::IXMLDOMElementPtr root);
};

/////////////////////////////////////////////////////////////////////////////
/*
#define NUM_TMPL_OPTION	32
class CMetaTmplItem
{
public:
	CMetaTmplItem();
	virtual ~CMetaTmplItem();

public:
	BYTE		notNULL;
	CString		name;
	WORD		num;
	CString		option[NUM_TMPL_OPTION];

	void		Input(BYTE nn,LPCSTR n,const CString& opt);
	BYTE		Output(CString& n,CString& opt);
	void		Reset();
	void		Copy(const CMetaTmplItem& ti);
	void		Save(MSXML2::IXMLDOMDocumentPtr odom,MSXML2::IXMLDOMElementPtr pRoot);
	void		Load(MSXML2::IXMLDOMElementPtr pItem);
};
*/

class CMetaTmplItem
{
public:
	CMetaTmplItem();
	virtual ~CMetaTmplItem();

public:
	DWORD			id;
	CString			title;
	CStringArray	name;
	CStringArray	value;

public:
	void Reset();
	BYTE IsEmpty() const;
	void GenDefault();
	void Add(LPCSTR szName,LPCSTR szValue);
	void Output(CString& str) const;
	void Save(MSXML2::IXMLDOMDocumentPtr odom,MSXML2::IXMLDOMElementPtr pRoot);
	void Load(MSXML2::IXMLDOMElementPtr pItem);
};

#define NUM_TMPL_ITEM	128
class CMetaTmpl
{
public:
	CMetaTmpl();
	virtual ~CMetaTmpl();

public:
	WORD			num;
	CMetaTmplItem	item[NUM_TMPL_ITEM];

public:
	void Reset();
	BYTE FindByID(DWORD id,LPWORD index) const;
	DWORD Add(LPCSTR title,const CStringArray& name,const CStringArray& value);
	void LoadFromXML(LPCSTR xmlFile);
	void SaveToXML(LPCSTR xmlFile);
};

/*
#define NUM_TMPL_ITEM	256
class CMetaTmpl
{
public:
	CMetaTmpl();
	virtual ~CMetaTmpl();

public:
	CString			path;
	CString			name;
	WORD			num;
	CMetaTmplItem	item[NUM_TMPL_ITEM];

public:
	void	SaveToXML(LPCSTR xmlFile);
	void	LoadFromXML(LPCSTR xmlFile);

	void	Del(WORD index);
	void	Copy(const CMetaTmpl& t);
};
*/

class CAnnoTmplItem
{
public:
	CAnnoTmplItem();
	virtual ~CAnnoTmplItem();
	
public:
	CString	cls;
	CStringArray	dat;

public:
	void Reset();
	void Add(const CString& d);
	BYTE IsContain(LPCSTR d,LPWORD index);
	void Save(MSXML2::IXMLDOMDocumentPtr odom,MSXML2::IXMLDOMElementPtr root);
	void Load(MSXML2::IXMLDOMElementPtr root);
};

#define NUM_ANNO_TMPL		512
class CAnnoTmpl
{
public:
	CAnnoTmpl();
	virtual ~CAnnoTmpl();
	
public:
	WORD num;
	CAnnoTmplItem	item[NUM_ANNO_TMPL];

public:
	void Reset();
	void Add(const CString& c,const CString& d);
	BYTE HasCls(LPCSTR c,LPWORD index);
	BYTE IsContain(LPCSTR cls,LPCSTR dat,LPWORD index,LPWORD subIndex);

	void SaveToXML(LPCSTR xmlFile);
	BYTE LoadFromXML(LPCSTR xmlFile);
};

/////////////////////////////////////////////////////////////////////////////
class CEJMeta
{
public:
	CEJMeta();
	virtual ~CEJMeta();

public:
	DWORD			tmplID;
	CString			title;
	CString			thmCls;
	CString			rgnCls;
	CString			eraCls;
	CStringArray	name;
	CStringArray	value;
	
public:
	void	Reset();
	BYTE	HasCls() const;
	BYTE	IsEmpty() const;
	void	Output(CString& str);
	void	Input(const CString& str);
	void	Apply(const CMetaTmplItem& ti);
	void	SaveToXML(LPCSTR xmlFile);
	BYTE	LoadFromXML(LPCSTR xmlFile);
};

#define NUM_EJ_PAGE		1024
/////////////////////////////////////////////////////////////////////////////
class CEJData
{
public:
	CEJData();
	virtual ~CEJData();

public:
	CString	baseDir;

	CEJMeta	meta;

	WORD	num;		// num of pages
	CEJPage	page[NUM_EJ_PAGE];

public:
	void	Save(LPCSTR szDir=NULL);
	BYTE	Load(LPCSTR szDir);
	void	Unload(WORD selIndex);
	void	LoadPages(LPCSTR dir);
	void	FlushPages();

	void	Input(const CString& str);
	void	Output(CString& str);

	void	SaveContent(LPCSTR xmlFile);
	BYTE	LoadContent(LPCSTR xmlFile);
	
	void	SaveCatalog(LPCSTR xmlFile);

	BYTE	FindByID(DWORD id,LPWORD index);

	WORD	CalcBackward(WORD index);
};

/////////////////////////////////////////////////////////////////////////////
// CEJWorkApp:
// See EJWork.cpp for the implementation of this class
//
#define OPER_INTRO		0
#define OPER_CONTENT	1
#define OPER_CATALOG	2

class CEJWorkApp : public CWinApp
{
public:
	CEJWorkApp();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CEJWorkApp)
	public:
	virtual BOOL InitInstance();
	//}}AFX_VIRTUAL

// Implementation
	//{{AFX_MSG(CEJWorkApp)
	afx_msg void OnAppAbout();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

public:
	CString hostName;
	CString	baseDir;
	CEJData	ejd;
	WORD	pageInView;
	BYTE	oper;

	WORD		numTmpl;
	CMetaTmpl	meta;
	CAnnoTmpl	anno;

	BYTE		modified;
	
};

#include "ijl.h"

#include "EJWorkDoc.h"
#include "CustSplit.h"
#include "EJEditView.h"
#include "EJFileView.h"
#include "EJAnnoView.h"
#include "EJListView.h"
#include "MainFrm.h"
#include "MetaMgrDialog.h"
#include "MetaConfDialog.h"
#include "MetaSelDialog.h"
#include "MetaSaveDialog.h"
#include "AnnoDialog.h"
#include "MetaDialog.h"
#include "CatlDialog.h"
#include "ClsDialog.h"

extern CEJWorkApp theApp;
/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_EJWORK_H__3A6B6BDA_E548_4606_98A4_717C0AC8D892__INCLUDED_)
